package com.qk.handler;

import com.qk.common.Result;
import com.qk.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: zhangchuang
 * @Date: 2025/10/07 09:49
 * @Description: 全局异常处理类
 */
@RestControllerAdvice
@Slf4j
@SuppressWarnings("all")
public class GlobalExceptionHandler {

    private static final String DEFAULT_ERROR_MESSAGE = "网络出现异常，请稍后重试";

    @ExceptionHandler(value = Exception.class)
    public Result handleException(Exception e) {
        log.error("服务器发生异常：{}", e.getMessage());
        return Result.error(DEFAULT_ERROR_MESSAGE);
    }

    @ExceptionHandler(value = CommonException.class)
    public Result handleCommonException(CommonException e) {
        log.error("服务器发生异常：{}", e.getMessage());
        return Result.error(e.getMessage());
    }

}
